36 Lecture
CS201
Midterm & Final Term Short Notes
Stream Manipulations
Stream manipulations, also known as manipulators, are functions that are used to modify the formatting and behavior of input and output streams in C++. Some common manipulations include setting the width and precision of output data, controlling
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- Which of the following stream manipulators is used to set the width of output data? A. setw() B. setwidth() C. setfill() D. setprecision()
Answer: A. setw()
- What is the purpose of the setprecision() stream manipulator? A. To set the width of output data B. To set the number of decimal places for output data C. To skip whitespace when reading input data D. To set the fill character for output data
Answer: B. To set the number of decimal places for output data
- Which of the following stream manipulators is used to control the format of numeric output? A. setprecision() B. setformat() C. setfill() D. setiosflags()
Answer: D. setiosflags()
- What is the purpose of the showpoint stream flag? A. To show the decimal point for floating-point output B. To show the sign of negative numbers C. To skip leading whitespace when reading input data D. To show trailing zeros for floating-point output
Answer: A. To show the decimal point for floating-point output
- Which of the following stream manipulators is used to skip whitespace when reading input data? A. setw() B. setwidth() C. skipws D. noskipws
Answer: C. skipws
- What is the purpose of the setfill() stream manipulator? A. To set the width of output data B. To set the number of decimal places for output data C. To skip whitespace when reading input data D. To set the fill character for output data
Answer: D. To set the fill character for output data
- Which of the following stream manipulators is used to reset the format flags for a stream? A. resetiosflags() B. setiosflags() C. clear() D. setbase()
Answer: A. resetiosflags()
- What is the purpose of the setw() and setfill() manipulators used together? A. To set the width of output data B. To set the number of decimal places for output data C. To skip whitespace when reading input data D. To set the fill character and width for output data
Answer: D. To set the fill character and width for output data
- Which of the following stream manipulators is used to control the format of output data? A. setprecision() B. setiosflags() C. setfill() D. setw()
Answer: B. setiosflags()
- What is the purpose of the noshowpoint stream flag? A. To hide the decimal point for floating-point output B. To hide the sign of negative numbers C. To skip trailing whitespace when reading input data D. To hide trailing zeros for floating-point output
Answer: A. To hide the decimal point for floating-point output
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What are stream manipulations in C++? Answer: Stream manipulations, also known as manipulators, are functions that are used to modify the formatting and behavior of input and output streams in C++.
How do you use the setw() manipulator to set the width of output data? Answer: You can use the setw() manipulator followed by an integer value to set the width of output data. For example: cout << setw(10) << "Hello";
What is the purpose of the setprecision() manipulator? Answer: The setprecision() manipulator is used to set the number of decimal places for floating-point output data.
How do you use the setiosflags() manipulator to set stream flags? Answer: You can use the setiosflags() manipulator followed by a flag constant to set stream flags. For example: cout << setiosflags(ios::fixed) << 3.14159;
What is the purpose of the skipws manipulator? Answer: The skipws manipulator is used to skip leading whitespace when reading input data.
How do you use the setfill() manipulator to set the fill character for output data? Answer: You can use the setfill() manipulator followed by a character value to set the fill character for output data. For example: cout << setfill('*') << setw(10) << "Hello";
What is the purpose of the resetiosflags() manipulator? Answer: The resetiosflags() manipulator is used to reset the format flags for a stream to their default values.
How do you use the noshowpoint manipulator to hide the decimal point for floating-point output data? Answer: You can use the noshowpoint manipulator to hide the decimal point for floating-point output data. For example: cout << noshowpoint << 3.14159;
What is the purpose of the setiosflags() manipulator with the ios::left flag? Answer: The setiosflags() manipulator with the ios::left flag is used to left-justify output data.
How do you use the setprecision() manipulator with fixed-point notation to set the number of decimal places for output data? Answer: You can use the setprecision() manipulator with the fixed-point notation to set the number of decimal places for output data. For example: cout << fixed << setprecision(2) << 3.14159;